package com.huanbao.nongwu.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huanbao.common.pojo.nwrabc.SysUser;
import com.huanbao.nongwu.dao.SysUserDao;
import com.huanbao.nongwu.pojo.SysUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/* ━━━━━━佛祖保佑━━━━━━
 *                  ,;,,;
 *                ,;;'(    社
 *      __      ,;;' ' \   会
 *   /'  '\'~~'~' \ /'\.)  主
 * ,;(      )    /  |.     义
 *,;' \    /-.,,(   ) \    码
 *     ) /       ) / )|    农
 *     ||        ||  \)
 *     (_\       (_\
 * ━━━━━━永无BUG━━━━━━
 * @author ：zjq
 * @date ：2021/3/24 10:10
 * @description: TODO
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 */
@Service
public class SysUserServiceImpl {

    @Autowired
    private SysUserDao sysUserDao;


    public PageInfo<SysUserVO> getAllUserWithRoleName(Map<String, Object> map) {
        int pageNum = (int) map.get("pageNum");
        int pageSize = (int) map.get("pageSize");

        PageHelper.startPage(pageNum, pageSize);
        List<SysUserVO> list = sysUserDao.getAllUserWithRoleName();
        PageInfo<SysUserVO> info = new PageInfo(list);
        return info;
    }


    public int insert(SysUser record) {
        int count = sysUserDao.insert(record);
        return count;
    }

    public SysUser checkUserByLoginName(String loginName) {
        QueryWrapper<SysUser> emp = new QueryWrapper<>();
        emp.eq("loginname", loginName);
        SysUser sysUser = sysUserDao.selectOne(emp);
        return sysUser;
    }


    public int deleteByPrimaryKey(Integer id) {
        return sysUserDao.deleteById(id);
    }

    public int updateByPrimaryKeySelective(SysUser record) {
        return sysUserDao.updateById(record);
    }

    public SysUser getUserByLoginName(String loginName) {

        QueryWrapper<SysUser> emp = new QueryWrapper<>();
        emp.eq("loginname", loginName);
        SysUser sysUser = sysUserDao.selectOne(emp);
        return sysUser;
    }

}
